package com.tianshi.yingxue.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class AliyunOssUtils {
    private static String endpoint = FileUploadConstance.ENDPOINT;
    private static String accessKeyId = FileUploadConstance.ACCESS_KEY_ID;
    private static String accessKeySecret = FileUploadConstance.ACCESS_KEY_SECRET;
    public static void uploadFileBytes(MultipartFile headImg,String bucketName,String objName)throws IOException {
        OSS ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        byte[] content = headImg.getBytes();
        ossClient.putObject(bucketName,objName,new ByteArrayInputStream(content));
        ossClient.shutdown();
    }
    public static void deleteFile(String bucketName,String objName) {
        OSS ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        ossClient.deleteObject(bucketName,objName);
        ossClient.shutdown();
    }
}
